package com.boot.mgt.controller.app

import com.boot.core.result.ResultTo
import com.boot.mgt.model.TaNote
import com.boot.mgt.model.TaPolice
import com.boot.mgt.service.TaNoteService
import com.boot.mgt.service.TaPoliceService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 *
 * @version V1.0
 * @author kawins
 * createTime 2021/2/18
 */
@RestController
@RequestMapping("/app/rapporter")
class NoteRapporterController {

    @Autowired
    private lateinit var taNoteService: TaNoteService

    @Autowired
    private lateinit var taPoliceService: TaPoliceService

    /**
     * 获取上报信息
     */
    @GetMapping("/{id}")
    fun selectNoteById(@PathVariable id: Int?): ResultTo {
        return taNoteService.selectById(id)
    }

    /**
     * 增加上报信息
     */
    @PostMapping("/insert")
    fun insertTaNote(@RequestBody taNote: TaNote): ResultTo {
        return taNoteService.insertRapporter(taNote)
    }

    /**
     * 删除上报信息
     */
    @DeleteMapping("/{id}")
    fun deleteTaNote(@PathVariable id: Int): ResultTo {
        return taNoteService.deleteRapporter(id)
    }

    @GetMapping("/userAll")
    fun selectUserAll(): ResultTo {
        val searchAllPolice = taPoliceService.searchAllPolice(null)
        val list: MutableList<TaPolice> = mutableListOf()
        for (police in searchAllPolice) {
            TaPolice().apply {
                policeNumber = police["user_name"] as String
                val fullName = police["full_name"]
                name = if (fullName != null) {
                    fullName as String
                } else {
                    ""
                }
                list.add(this)
            }
        }
        return ResultTo().apply {
            setData("list", list)
        }
    }


}